package com.stage.communication;

import com.stage.helper.InputManager;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;
/**
 * Created by Stage on 2017/3/24.
 */
public class ServiceRead implements Runnable {
    private Socket socket;
    private InputManager inputManager = new InputManager();
    public ServiceRead(Socket socket) {
        this.socket = socket;
    }
    @Override
    public void run() {
        try {
            InputStreamReader reader = new InputStreamReader(socket.getInputStream());
            BufferedReader bufferedReader = new BufferedReader(reader);
            try {
                while (true) {
                    String client = "<" + socket.getInetAddress().toString() + " : " + socket.getPort() + ">";
                    String request = bufferedReader.readLine();
                    System.out.println(client + " say：  " + request);
                }
            } finally {
                bufferedReader.close();
                socket.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
